//
//  HZLeftRightView.m
//  Stock_Stategy
//
//  Created by MayerF on 2017/12/11.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZLeftRightView.h"

@interface HZLeftRightView()
@property (nonatomic, strong)UILabel *pLeftLabel;
@property (nonatomic, strong)UILabel *pRightLabel;
@property (nonatomic, strong)UITextField *pTextField;
@end

@implementation HZLeftRightView

#pragma mark -
#pragma mark 生命周期
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initCommon];
        [self initConstraints];
    }
    return self;
}
- (void)initCommon
{
    _pLeftLabel = [UILabel new];
    _pRightLabel = [UILabel new];
    
    _pLeftLabel.textAlignment = NSTextAlignmentLeft;
    _pRightLabel.textAlignment = NSTextAlignmentRight;
    _pLeftLabel.font = [UIFont systemFontOfSize:15];
    _pRightLabel.font = [UIFont systemFontOfSize:15];
}
- (void)initConstraints
{
    [self addSubview:_pLeftLabel];
    [self addSubview:_pRightLabel];
    
    [_pLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(10);
        make.right.mas_equalTo(_pRightLabel.mas_left);
    }];
    [_pRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.height.mas_equalTo(_pLeftLabel);
        make.right.mas_equalTo(self).offset(-10);
        make.width.mas_equalTo(110);
    }];
}

- (void)setLefttext:(NSString *)lefttext rigthtext:(NSString *)rigthtext
{
    [self setLefttext:lefttext];
    [self setRighttext:rigthtext];
}
- (void)setLefttext:(NSString *)lefttext
{
    _pLeftLabel.text = lefttext;
}
- (void)setRighttext:(NSString *)rigthtext
{
    _pRightLabel.text = rigthtext;
}
- (void)showTextFiledWithPlaceholder:(NSString *)placeholder
{
    _pRightLabel.hidden = YES;
    self.pTextField.placeholder = placeholder;
    
    [self addSubview:self.pTextField];
    [_pTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.mas_equalTo(_pRightLabel);
        make.width.mas_equalTo(150);
    }];
}
- (void)setTextfieldText:(NSString *)text
{
    _pTextField.text = text;
}
- (void)clearTextField
{
    _pTextField.text = @"";
}
- (NSString *)getTextFieldText
{
    return _pTextField.text;
}

- (UITextField *)pTextField {
    if (!_pTextField) {
        _pTextField = [UITextField new];
        _pTextField.textAlignment = NSTextAlignmentRight;
        _pTextField.font = [UIFont systemFontOfSize:15];
    }
    return _pTextField;
}

@end
